#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <set>

using namespace std;

class Solution {
    public:
        int reverse(int x) {
            int sign = 1;
            unsigned long long ans = 0;
            if (x < 0) {x = -x; sign = -1;}
            while ( x > 0) {
                ans = ans * 10 + x%10;
                if ((ans > INT_MAX && sign == 1) || ( ans > -INT_MIN && sign == -1)) return (sign == -1) ? INT_MIN : INT_MAX;
                x /= 10;
            }
            return sign * ans;
        }
};

//test in 1337 online test and pass all the test case
int main(int argc, char **argv)
{
    Solution mySolution;
    cout << "-----------------Test 1--------------------" << endl;
    cout << mySolution.reverse(1234) << endl;

    cout << "-----------------Test 2--------------------" << endl;
    cout << mySolution.reverse(-1234) << endl;


    cout << "-----------------Test 3--------------------" << endl;
    cout << mySolution.reverse(1000) << endl;


    cout << "-----------------Test 4--------------------" << endl;
    cout << mySolution.reverse(1000000003) << endl;


    cout << "-----------------Test 5--------------------" << endl;



}
